package com.synnex.mobile.servier.core.msgBoard.dao.impl;

import com.synnex.mobile.generic.dao.impl.GenericHibernateDaoImpl;
import com.synnex.mobile.servier.core.msgBoard.dao.MsgBoardDao;
import com.synnex.mobile.servier.core.msgBoard.dto.MsgDTO;
import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kerryf
 * To change this template use File | Settings | File Templates.
 */
public class MsgBoardDaoImpl extends GenericHibernateDaoImpl<MsgDTO, Integer> implements MsgBoardDao {

    public List<MsgDTO> getMsgList(MsgDTO criteria, int begin, int size) {
        Criteria c = this.getSession().createCriteria(MsgDTO.class);

        return c.setFirstResult(begin)
                .setMaxResults(size)
                .list();
    }

    public Integer getMsgSize(MsgDTO msgDTO) {
        Criteria c = this.getSession().createCriteria(MsgDTO.class);
        Integer count = (Integer) c.setProjection(Projections.count("id")).uniqueResult();
        return count;
    }

    public void saveMsg(MsgDTO msgDTO) {
        this.save(msgDTO);
    }
}
